//
//  ForMyCommentCell.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/4/20.
//  Copyright © 2016年 game. All rights reserved.
//

#import "ForMyCommentCell.h"
#import "TYAttributedLabel.h"
#import "forCommentListNotevarModel.h"
#import "MBButtonWithFontAdapter.h"
#import "MBLabelWithFontAdapter.h"
#import "MBTextFieldWithFontAdapter.h"
#import "MBTextViewWithFontAdapter.h"
#import "NSMutableAttributedString+TY.h"
#import "NSAttributedString+Attributes.h"
#import "YYText.h"
#import "YYLabel.h"
#import "NSString+HtmlCharact.h"
#import "NSString+DealTheMessage.h"
#import "MBButtonWithFontAdapter.h"
#import "MBLabelWithFontAdapter.h"
#import "MBTextFieldWithFontAdapter.h"
#import "MBTextViewWithFontAdapter.h"
#import "UIButton+WebCache.h"
@interface ForMyCommentCell ()<TYAttributedLabelDelegate>
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentTop;
@property (weak, nonatomic) IBOutlet UIButton *userHead;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headWidth;
@property (weak, nonatomic) IBOutlet MBButtonWithFontAdapter *userName;
@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *time;
@property (weak, nonatomic) IBOutlet MBButtonWithFontAdapter *click;
@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *title;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *iamgeHeight;
@property (weak, nonatomic) IBOutlet UILabel *footShow;

@property (weak, nonatomic) IBOutlet YYLabel *content;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *footHight;
@property (weak, nonatomic) IBOutlet UIImageView *backImage;

@property (nonatomic,strong) forCommentListNotevarModel *noteModel;

@end

@implementation ForMyCommentCell

- (void)awakeFromNib {
    self.selectionStyle = 0;
    self.footShow.backgroundColor = tabPlainBackColor;
    self.footHight.constant = SCREEN_HEIGHT*0.03;
    
    self.headHeight.constant = SCREEN_WIDTH*0.07;
    self.headWidth.constant = self.headHeight.constant;
    radius(self.userHead, self.headHeight.constant/2);
    
    self.click.layer.borderColor = mainColor.CGColor;
    self.click.layer.borderWidth = 0.7;
    
    self.backImage.image = [[UIImage imageNamed:@"bg_word"]stretchableImageWithLeftCapWidth:0 topCapHeight:10];
    
    if (kDIEIsIPhone6) {
        self.contentTop.constant = 20;
    }else if (kDIEIsIPhone6P){
        self.contentTop.constant = 30;
    }
    
    self.content.textVerticalAlignment = YYTextVerticalAlignmentCenter;
    self.content.numberOfLines = 0;
    self.content.font = font(SCREEN_WIDTH*0.043);
    
}

-(void)setModel:(forCommentListModel *)model{
    _model = model;

    [self.userHead sd_setImageWithURL:[NSURL URLWithString:_model.avatar] forState:UIControlStateNormal];
    [self.userName setTitle:_model.author forState:UIControlStateNormal];
    self.content.backgroundColor = [UIColor clearColor];
    self.time.text = _model.dateline;
    
    _noteModel = _model.notevar;
    
    self.title.text = _noteModel.subject;
    
    self.tid = _noteModel.tid;
    
    
NSString *sss = [NSString stringWithFormat:@"评论了您的帖子\t\t\n%@",_noteModel.message];
    
    NSRange rrrrr = [sss rangeOfString:@"\t\t\n"];
    NSRange range = NSMakeRange(0, rrrrr.location+1);
    
    NSMutableAttributedString* mas = [[sss filterresult] dealTheMessage];
    [mas setTextColor:[UIColor colorWithRed:112/255.0f green:112/255.0f blue:112/255.0f alpha:1.0] range:range];
    
    [mas setFont:font(SCREEN_WIDTH*0.05)];
    
    [mas setFont:[UIFont systemFontOfSize:([UIScreen mainScreen].bounds.size.width)*0.043] range:range];
    self.content.attributedText = mas;
    CGSize size = CGSizeMake(SCREEN_WIDTH-44, CGFLOAT_MAX);
    YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:size text:mas];

    
    self.contentHeight.constant = layout.textBoundingSize.height;
    self.iamgeHeight.constant = layout.textBoundingSize.height+30;
    
    self.height = layout.textBoundingSize.height+SCREEN_HEIGHT*0.25;
}

- (IBAction)spaceGo:(UIButton *)sender {
    
    if ([self.deleget respondsToSelector:@selector(SpaceActionWhithId:)]) {
        [self.deleget SpaceActionWhithId:_model.authorid];
    }
}

- (IBAction)replay:(MBButtonWithFontAdapter *)sender {
    
    if ([self.deleget respondsToSelector:@selector(ReplayActionWhithTid:AndPid:AndFid:AndText:)]) {
        [self.deleget ReplayActionWhithTid:_noteModel.tid AndPid:_noteModel.pid AndFid:_noteModel.fid AndText:[NSString stringWithFormat:@"@%@",_model.author]];
    }
    
}



@end